<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
	String basePath = "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="/">
    <!-- 下拉框 -->
    <link rel="stylesheet" href="static/ace/css/chosen.css"/>
    <!-- jsp文件头和头部 -->
    <%@ include file="../index/top.jsp" %>
</head>
<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <form action="plantbase/${msg }.do" name="plantbaseForm" id="plantbaseForm" method="post">
                            <c:if test="${address.id !=null}">
                                <input type="hidden" name="id" id="id" value="${address.id }"/>
                            </c:if>
                             <input type="hidden" name="baseId" value="${pd.baseId }"/>
                            <div id="zhongxin" style="padding-top: 13px;">
                                <table id="table_report" class="table table-striped table-bordered table-hover">
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">基地:</td>
                                        <td><input type="text"  value="${address.name }"
                                                   maxlength="32" readonly="readonly"
                                                   style="width:98%;"/></td>
                                    </tr>
                                   	<tr>
										<td style="width:79px;text-align: right;padding-top: 13px;">发货区域:</td>
										<td>
										<select class="province" onchange="changeForm(this.value)"></select>
										<select id="city" onchange="changeForm1(this.value)"></select>
										<select id="country" onchange="changeForm2(this.value)"></select>
										<select id="town"></select>
											<input type="hidden" name="cityId" id="city_id" /> 
											<input type="hidden" name="provincId" id="provinc_id" />
											<input type="hidden" name="countryId" id="country_id" />
											<input type="hidden" name="townId" id="town_id" />
										</td>
									</tr>
									<tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">详细地址:</td>
                                        <td><input type="text"  value="${address.delivery_address }"
                                                   maxlength="32" name="delivery_address" id="delivery_address" 
                                                   style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">发货人:</td>
                                        <td><input type="text"  value="${address.delivery_person }"
                                                   maxlength="32" name="delivery_person" id="delivery_person" 
                                                   style="width:98%;"/></td>
                                    </tr>
                                       <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">发货人手机号:</td>
                                        <td><input type="text"  value="${address.delivery_phone }"
                                                   maxlength="32" name="delivery_phone" id="delivery_phone" 
                                                   style="width:98%;"/></td>
                                    </tr>
                                       <tr>
                                        <td style="width:100px;text-align: right;padding-top: 13px;">状态:</td>
                                        <td>
                                            <span><input name="state"  id="status1" type="radio" value="01"/>默认 </span>&nbsp;|&nbsp;
                                            <span><input name="state"  id="status2" type="radio" value="00" checked="checked"/>非默认 </span>
                                        </td>
                                    </tr>
                                   
                                </table>
                                <table id="table_report1" class="table table-striped table-bordered table-hover">
                                    <tr>
                                        <td style="text-align: center;" colspan="10">
                                                <a class="btn btn-mini btn-primary" onclick="save();">保存</a>
                                            <a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div id="zhongxin2" class="center" style="display:none"><br/><br/><br/><br/><img
                                    src="static/images/jiazai.gif"/><br/><h4 class="lighter block green"></h4></div>
                        </form>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
</div>
<!-- /.main-container -->
<!-- basic scripts -->
<!-- 页面底部js¨ -->
<%@ include file="../index/foot.jsp" %>
<!-- ace scripts -->
<script src="static/ace/js/ace/ace.js"></script>
<!-- inline scripts related to this page -->
<!-- 下拉框 -->
<script src="static/ace/js/chosen.jquery.js"></script>
<!--提示框-->
<script type="text/javascript" src="static/js/jquery.tips.js"></script>
</body>
<script type="text/javascript">
    $(top.hangge());
    $(function (){
    	if ('${address.status}'== '00') {
            $("#status2").attr("checked", true);
        } else {
            $("#status1").attr("checked", true);
        }
    	$.ajax({   
		     url:'<%=basePath%>plantbase/realList.do',   
		     type:'post',   
		     data:{'parentId':0},   
		     error:function(){   
		        alert('error');   
		     },   
		     success:function(data){
		    	 $(".province").empty();
		    	 $(".province").append('<option value=0>请选择</option>'); 
		    	 $.each(data.list,function(i,v){
		    		 var ele = document.createElement('option')
		    		 ele.value = v.id;
		    		 ele.innerHTML = v.areaName;
		    		 if('${address.province_id}' ==v.id){
			    	    	ele.selected = true;
			    		} 
		    	    $(".province").append(ele)
		    	}); 
		     }
		 });
		$.ajax({   
		     url:'<%=basePath%>plantbase/realList.do',    
		     type:'post',   
		     data:{'parentId':'${address.province_id}'},   
		     error:function(){   
		        alert('error');   
		     },   
		     success:function(data){
		    	 $("#city").empty();
		    	 $("#city").append('<option value=0>请选择</option>');
		    	$.each(data.list,function(i,v){
		    		var ele = document.createElement('option')
		    		  ele.value = v.id;
		    		 ele.innerHTML = v.areaName;
		    		 if('${address.city_id}' ==v.id){
			    	    	ele.selected = true;
			    		}
		    	    $("#city").append(ele)
		    	});
		    	
		     }
		 });
		$.ajax({   
		     url:'<%=basePath%>plantbase/realList.do',    
		     type:'post',   
		     data:{'parentId':'${address.city_id}'},   
		     error:function(){   
		        alert('error');   
		     },   
		     success:function(data){
		    	 $("#country").empty();
		    	 $("#country").append('<option value=0>请选择</option>');
		    	$.each(data.list,function(i,v){
		    		var ele = document.createElement('option')
		    		  ele.value = v.id;
		    		 ele.innerHTML = v.areaName;
		    		 if('${address.country_id}' ==v.id){
			    	    	ele.selected = true;
			    		}
		    	    $("#country").append(ele)
		    	});
		    	
		     }
		 });
		$.ajax({   
		     url:'<%=basePath%>plantbase/realList.do',    
		     type:'post',   
		     data:{'parentId':'${address.country_id}'},   
		     error:function(){   
		        alert('error');   
		     },   
		     success:function(data){
		    	 $("#town").empty();
		    	 $("#town").append('<option value=0>请选择</option>');
		    	$.each(data.list,function(i,v){
		    		var ele = document.createElement('option')
		    		  ele.value = v.id;
		    		 ele.innerHTML = v.areaName;
		    		 if('${address.town_id}' ==v.id){
			    	    	ele.selected = true;
			    		}
		    	    $("#town").append(ele)
		    	});
		    	
		     }
		 });
    });


    function changeForm(provinc_id){
    	debugger
    	$.ajax({   
    	     url:'<%=basePath%>plantbase/realList.do',    
    	     type:'post',   
    	     data:{'parentId':provinc_id},   
    	     error:function(){   
    	        alert('error');   
    	     },   
    	     success:function(data){
    	    	 $("#city").empty();
    	    	 $("#city").append('<option value=0>请选择</option>');
    	    	 $("#country").empty();
    	    	 $("#country").append('<option value=0>请选择</option>');
    	    	 $("#town").empty();
    	    	 $("#town").append('<option value=0>请选择</option>');
    	    	$.each(data.list,function(i,v){
    	    		var ele = document.createElement('option')
    	    		  ele.value = v.id;
    	    		 ele.innerHTML = v.areaName;
    	    	    $("#city").append(ele)
    	    	});
    	    	
    	     }
    	 });
    	
    }
    
    function changeForm1(city_id){
    	var province= $(".province").val();
    	if(province=="" || province=="请选择" || province=="0"){
    		 $("#city").empty();
	    	 $("#city").append('<option value=0>请选择</option>');
	    	 $("#country").empty();
	    	 $("#country").append('<option value=0>请选择</option>');
	    	 $("#town").empty();
	    	 $("#town").append('<option value=0>请选择</option>');
    		return;
    	}
    	
    	$.ajax({   
    	     url:'<%=basePath%>plantbase/realList.do',    
    	     type:'post',   
    	     data:{'parentId':city_id},   
    	     error:function(){   
    	        alert('error');   
    	     },   
    	     success:function(data){
    	    	 $("#country").empty();
    	    	 $("#country").append('<option value=0>请选择</option>');
    	    	 $("#town").empty();
    	    	 $("#town").append('<option value=0>请选择</option>');
    	    	$.each(data.list,function(i,v){
    	    		var ele = document.createElement('option')
    	    		  ele.value = v.id;
    	    		 ele.innerHTML = v.areaName;
    	    	    $("#country").append(ele)
    	    	});
    	    	
    	     }
    	 });
    	
    }
    function changeForm2(country_id){
    	var province= $(".province").val();
    	if(province=="" || province=="请选择" || province=="0"){
    		 $("#country").empty();
	    	 $("#country").append('<option value=0>请选择</option>');
	    	 $("#town").empty();
	    	 $("#town").append('<option value=0>请选择</option>');
    		return;
    	}
    	$.ajax({   
    	     url:'<%=basePath%>plantbase/realList.do',    
    	     type:'post',   
    	     data:{'parentId':country_id},   
    	     error:function(){   
    	        alert('error');   
    	     },   
    	     success:function(data){
    	    	 $("#town").empty();
    	    	 $("#town").append('<option value=0>请选择</option>');
    	    	$.each(data.list,function(i,v){
    	    		var ele = document.createElement('option')
    	    		  ele.value = v.id;
    	    		 ele.innerHTML = v.areaName;
    	    	    $("#town").append(ele)
    	    	});
    	    	
    	     }
    	 });
    	
    }
    
    function save(){
    	var myreg = /^1[3|4|5|7|8]\d{9}$/;
    	 var province = $(".province").find("option:selected").text();
    	 if(province == "undefined" || province == "" || province == "请选择"){
		    	alert("请选择发货地区");
		    	return false;
		 } else {
			 var province_id = $(".province").find("option:selected").val();
			 $("#provinc_id").val(province_id);
		 }
    	 var city = $("#city").find("option:selected").text();
    	 if(city == "undefined" || city == "" || city == "请选择"){
		    	alert("请选择发货城市");
		    	return false;
		 } else {
			 var city_id = $("#city").find("option:selected").val();
			 $("#city_id").val(city_id);
		 }
    	 var country = $("#country").find("option:selected").text();
    	 if(country == "undefined" || country == "" || country == "请选择"){
		    	alert("请选择发货区县");
		    	return false;
		 } else {
			 var country_id = $("#country").find("option:selected").val();
			 $("#country_id").val(country_id);
		 }
    	/*  var town = $("#town").find("option:selected").text();
    	 if(town == "undefined" || town == "" || town == "请选择"){
		    	alert("请选择发货城镇");
		    	return false;
		 } else {
			 var town_id = $("#town").find("option:selected").val();
			 $("#town_id").val(town_id);
		 } */
    	 if($.trim($("#delivery_address").val()) == ""){
    		 alert("请填写详细发货地址");
		    	return false;
    	 }
    	 if($.trim($("#delivery_person").val()) == ""){
    		 alert("请填写发货人");
		    	return false;
    	 }
    	 if($.trim($("#delivery_phone").val()) == ""){
    		 alert("请填写发货人手机号");
		    	return false;
    	 }
    	 if(!myreg.test($("#delivery_phone").val())){
    		 alert("手机号填写有误");
		    	return false;
    	 }
    	 $("#plantbaseForm").submit();
         $("#zhongxin").hide();
         $("#zhongxin2").show();
    		
    }
    

</script>
</html>